<?php
 define('PRODUCTS',62);
 define('COLS', 8);
 $count = 0;
 $rows = ceil( PRODUCTS / COLS )  ;
 $table =  "<table width='50%'
 align='center'>";
 for($i=1 ; $i<=$rows ; $i++) {
   $color = ($i%2==0)?'red':'green';
   $table .= "<tr>";

   for($j=1 ; $j<=COLS ;$j++) {
if($j==1){
  $count = $i;
} else {
  $count += $rows;
}

    if($count<=PRODUCTS) {
     $table .="<td style='background:$color'>
     {$count}</td>";
  } else {
     $table .= "<td style='background:$color'>
     &nbsp;</td>";
  }
   }
   $table .="</tr>";
 }
 $table .="</table>";


 echo $table;
